/* 枚举 火柴棍等式 */

#include<iostream>
using namespace std;

int CalcSticks(int value)
{
    int sticks[] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6};
    int res = 0;

    while (value >= 10)
    {
        res += sticks[value % 10];
        value /= 10;
    }
    res += sticks[value];

    return res;
}

void EnumStickEq(int stickNum)
{
    /* +和＝各占2根火柴棍 */
    stickNum -= 4;

    /* 1个"1"需要4根火柴棍，剩下的火柴棍最多能组成多少个“1”？ */
    int maxNumOf1 = stickNum / 4;

    int maxNum = 1;
    for (int i = 1; i < maxNumOf1; i++)
    {
        maxNum = maxNum * 10 + 1;
    }

    for (int i = 0; i <= maxNum; i++)
    {
        for (int j = 0; j <= maxNum; j++)
        {
            int value = i + j;
            if (CalcSticks(i) + CalcSticks(j) + CalcSticks(value) == stickNum)
            {
                cout<< i << " + " << j << " = " << value <<endl;
            }
        }
    }
}

int main(void)
{
    cout<< "Enum 14 Sticks: \n";
    EnumStickEq(14);
    cout<< "\nEnum 18 Sticks: \n";
    EnumStickEq(18);
    cout<< "\nEnum 24 Sticks: \n";
    EnumStickEq(24);
}
